IF OBJECT_ID('dbo.csp_rptMetric_DefaultComparisonPeriod') IS NOT NULL
BEGIN
    DROP PROCEDURE dbo.csp_rptMetric_DefaultComparisonPeriod
END
GO

CREATE PROCEDURE dbo.csp_rptMetric_DefaultComparisonPeriod
(
	@PeriodType varchar(50)
)
AS

SELECT TOP 1
	PeriodStartDate
FROM
(
	SELECT TOP 2
		PeriodStartDate
	FROM
		rptMetric_Snapshots
	WHERE
		PeriodType = @PeriodType
	ORDER BY
		PeriodStartDate DESC
) AS x
ORDER BY
	PeriodStartDate
GO
